/*************************************************************************
 * File Name:    Remove_Duplicates_from_Sorted_Array.cc
 * Author:       zero91
 * Mail:         jianzhang9102@gmail.com
 * Created Time: 2013/11/8 0:08:34
 * 
 * Description:  
 |------------------------------------------------------------------------
 | Problem: Remove Duplicates from Sorted Array
 |
 | Given a sorted array, remove the duplicates in place such that each
 | element appear only once and return the new length.
 |
 | Do not allocate extra space for another array, you must do this in
 | place with constant memory.
 |
 | For example,
 | Given input array A = [1,1,2],
 |
 | Your function should return length = 2, and A is now [1,2].
 |------------------------------------------------------------------------
 ************************************************************************/

#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>

using namespace std;

class Solution {
public:
    int removeDuplicates(int A[], int n)
    {
        if (n <= 1) return n;
        
        int ans = 1;
        for (int i = 1; i < n; ++i) {
            if (A[i] != A[i - 1]) {
                A[ans++] = A[i];
            }
        }
        return ans;
    }
};

